package com.net.xpay.common.domain;

import com.net.common.domain.CommonDomain;
import com.net.xpay.common.enums.user.ClientFrom;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.LocalDateTime;

/**
 * 2019/8/21 16:59

 */
@Getter
@Setter
@NoArgsConstructor
public class LoginLog extends CommonDomain {
    @ApiModelProperty(notes = "用户id")
    private Long userId;

    @ApiModelProperty(notes = "注册手机号")
    private String mobile;

    @ApiModelProperty(notes = "上次登录时间", example = "2018-12-17 11:53:18")
    private LocalDateTime loginTime;

    @ApiModelProperty(notes = "上次的登录来源")
    private ClientFrom loginClient;

    @ApiModelProperty(notes = "最后一次登陆ip", example = "192.0.0.3")
    private String lastLoginIp;

    public static LoginLog getInstance(User user) {
        LoginLog loginLog = new LoginLog();
        loginLog.setUserId(user.getId());
        loginLog.setMobile(user.getMobile());
        loginLog.setLoginTime(user.getLastLoginTime());
        loginLog.setLoginClient(user.getLastLoginClient());
        loginLog.setLastLoginIp(user.getLastLoginIp());
        return loginLog;
    }
}
